/**
 * FileName: ScDeployController
 *
 * @author: 阿张
 * Date:     2021/2/24 14:14
 */
package com.qx.controller;

import com.qx.pojo.ScDeploy;
import com.qx.service.ScDeployService;
import com.qx.vo.DeployVo;
import org.springframework.web.bind.annotation.*;
import result.Result;
import result.ResultFactory;

import javax.annotation.Resource;
import java.util.Objects;

@RestController
@RequestMapping("deploy")
public class ScDeployController {

    @Resource
    private ScDeployService scDeployService;

    @RequestMapping(value = "getPageDeploy",method = RequestMethod.POST)
    public Result pageSearch(@RequestBody DeployVo deployVo , Integer pageNum , Integer pageSize){
        return ResultFactory.buildSuccessResult(scDeployService.pageSearch(deployVo, pageNum, pageSize));
    }

    @RequestMapping(value = "saveDeploy",method = RequestMethod.POST)
    public Result save(@RequestBody ScDeploy scDeploy){
        if (Objects.nonNull(scDeploy)){
            boolean save = scDeployService.save(scDeploy);
            if (save){
                return ResultFactory.buildSuccessResult("成功");
            }
            return ResultFactory.buildFailResult("发生了意外中的错误");
        }
        return ResultFactory.buildFailResult("请输入有效数据");
    }

    @RequestMapping(value = "delDeploy",method = RequestMethod.DELETE)
    public Result del(Integer id){
        if (Objects.nonNull(id)){
            boolean b = scDeployService.removeById(id);
            if (b){
                return ResultFactory.buildSuccessResult("成功");
            }
            return ResultFactory.buildFailResult("发生了意外中的错误");
        }
        return ResultFactory.buildFailResult("请输入有效数据");
    }

    @RequestMapping(value = "updateDeploy",method = RequestMethod.PUT)
    public Result update(@RequestBody ScDeploy scDeploy){
        if (Objects.nonNull(scDeploy)){
            boolean b = scDeployService.updateById(scDeploy);
            if (b){
                return ResultFactory.buildSuccessResult("成功");
            }
            return ResultFactory.buildFailResult("发生了意外中的错误");
        }
        return ResultFactory.buildFailResult("请输入有效数据");
    }

}
